/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { Module } from '@ohos/hvigor';

import { moduleOhosConfigManager } from '../../common/global/module-ohos-config-manager.js';
import { HapOhosConfig } from '../../options/build/hap-ohos-config.js';
import { AssembleHap } from '../../tasks/hook/assemble/assemble-hap.js';
import { BuildPreviewerRes } from '../../tasks/hook/previewer/build-previewer-res.js';
import { PreviewBuild } from '../../tasks/hook/previewer/preview-build.js';
import { UnitTestBuild } from '../../tasks/unitTest/unit-test-build.js';

import { AbstractModulePlugin } from './abstract-module-plugin.js';
import { OhosPluginId } from './ohos-plugin-id.js';

/**
 * 对外暴露hap级别的接口和任务的plugin
 *
 * @since 2021/12/16
 */
export abstract class AbstractHapModulePlugin extends AbstractModulePlugin {
  protected buildPreviewerRes: BuildPreviewerRes | undefined;
  protected previewBuild: PreviewBuild | undefined;
  protected unitTestBuild: UnitTestBuild | undefined;
  assembleHap: AssembleHap | undefined;

  protected constructor(module: Module) {
    super(OhosPluginId.OHOS_HAP_PLUGIN, module);
  }

  abstract initHapTasks(): void;

  initGlobalData() {
    const ohosConfig = this._module.getConfigOpt()?.getObject('ohos') as HapOhosConfig;

    if (!ohosConfig) {
      return;
    }

    moduleOhosConfigManager.loaderConfig(this.moduleName!, ohosConfig);
  }
}
